package scau.redi.social_platform.common.listener;
import scau.redi.social_platform.common.util.SessionContextUtil;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @Author: Redi
 * @Date: 2022/5/18 20:00
 * @Description: 监听器来监控session的创建销毁
 */

@WebListener
public class SessionListener implements HttpSessionListener {

    private SessionContextUtil myc = SessionContextUtil.getInstance();

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        myc.AddSession(httpSessionEvent.getSession());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        HttpSession session = httpSessionEvent.getSession();
        myc.DelSession(session);
    }
}

